package cn.yikaojiuguo.student.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.yikaojiuguo.student.R;
import cn.yikaojiuguo.student.bean.GoldOrder;

/**
 * Created by cfan_yang on 2016/1/13.
 */
public class GoldOrderAdapter extends SimpleBaseAdapter<GoldOrder> {

    private final static int MONEY_IN = 1;
    private final static int MONEY_OUT = 2;

    public GoldOrderAdapter(Context context, List<GoldOrder> list) {
        super(context, list);
    }

    public GoldOrderAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(mContext, R.layout.item_order_list,null);
            holder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            holder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
            holder.tv_money = (TextView) convertView.findViewById(R.id.tv_money);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        GoldOrder goldOrder = getItem(position);
        holder.tv_title.setText(goldOrder.message);
        holder.tv_time.setText(goldOrder.pubdate);
        if(goldOrder.etype == MONEY_IN) {
            holder.tv_money.setTextColor(0xFFF1AD24);
            holder.tv_money.setText("+ " + goldOrder.gold);
        } else if (goldOrder.etype == MONEY_OUT) {
            holder.tv_money.setTextColor(0xFF31C37C);
            holder.tv_money.setText("- " + goldOrder.gold);
        }
        return convertView;
    }

    static class ViewHolder {
        public TextView tv_title,tv_time,tv_money;
    }
}